import {createApp,h} from 'vue'
import App from './App.vue'
import router from "./config/router"
import axios from './config/axios'
import {localGet, localSet, localRemove} from './config/utils'


const app = createApp(App)
app.use(router)
// .use(axios)
// .use(localGet)
// .use(localSet)
// .use(localRemove)
app.config.globalProperties.axios = axios
app.config.globalProperties.$localGet = localGet
app.config.globalProperties.$localSet = localSet
app.config.globalProperties.$localRemove = localRemove

app.config.globalProperties.$sellStateStr = (sellStateValue, goodStateValue) => {
    let text = "";
    let type = "";
    if (sellStateValue == 0) {
        text = "下架中"
        type = "warning"
    } else if (sellStateValue == 1) {
        if ([-1, 0, 2].includes(goodStateValue)) {
            text = "商品暂不可销售"
            type = "danger"
        } else {
            text = "上架中"
            type = "success"
        }
    }
    return {
        text,
        type
    }
}

app.config.globalProperties.$goodStateStr = (stateValue) => {
    let text = "";
    let type = "";
    if (stateValue == -1) {
        text = "已删除"
        type = "danger"
    } else if (stateValue == 0) {
        text = "新增项，管理员待确认"
        type = "info"
    } else if (stateValue == 1) {
        text = "信息变更，管理员待确认"
        type = "warning"
    } else if (stateValue == 2) {
        text = "信息有误，需要修改"
        type = "danger"
    } else if (stateValue == 3) {
        text = "管理员已确认"
        type = "success"
    } else if (stateValue == 4) {
        text = "信息有误，建议修改"
        // type = "warning" 蓝色
    }
    return {
        text,
        type
    }
}

app.config.globalProperties.$orderStateObj = (stateValue) => {
    var text = ""
    var type = ""
    var effect = undefined
    if (stateValue == 0) {
        text = "已下单"
        type = ""
    } else if (stateValue == 1) {
        text = "消费中"
        type = "success"
    } else if (stateValue == 2) {
        text = "消费完成"
        type = "success"
        effect = "dark"
    } else if (stateValue == 3) {
        text = "手动关闭"
        type = "info"
    } else if (stateValue == 4) {
        text = "商家关闭"
        type = "warning"
    }
    const orderStateObj = {text, type}
    if (effect != undefined) {
        orderStateObj.effect = effect
    }

    return orderStateObj
}

app.config.globalProperties.$getViewportSize = function(){
    return {
        width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,//兼容性获取屏幕宽度
        height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight//兼容性获取屏幕高度
    };
};

app.directive('my-loading',{
    beforeMount(el,binding){

    }
})

app.mount('#app')


// /** 递归地从子节点获取文本 */
// function getChildrenTextContent(children) {
//     return children
//         .map(node => {
//             return typeof node.children === 'string'
//                 ? node.children
//                 : Array.isArray(node.children)
//                     ? getChildrenTextContent(node.children)
//                     : ''
//         })
//         .join('')
// }
//
// app.component('anchored-heading', {
//     render() {
//         // 从 children 的文本内容中创建短横线分隔 (kebab-case) id。
//         const headingId = getChildrenTextContent(this.$slots.default())
//             .toLowerCase()
//             .replace(/\W+/g, '-') // 用短横线替换非单词字符
//             .replace(/(^-|-$)/g, '') // 删除前后短横线
//         debugger
//         return h('h' + this.level, [
//             h(
//                 'a',
//                 {
//                     name: headingId,
//                     href: '#' + headingId
//                 },
//                 this.$slots.default()
//             )
//         ])
//     },
//     props: {
//         level: {
//             role: Number,
//             required: true
//         }
//     }
// })

